package com.alipay.sofa.demo.db.core.impl;

import com.alibaba.nacos.client.utils.StringUtils;
import com.alipay.sofa.demo.db.common.entity.StudentInfo;
import com.alipay.sofa.demo.db.common.entity.StudentInfoExample;
import com.alipay.sofa.demo.db.common.service.StudentQueryService;
import com.alipay.sofa.demo.db.core.dao.StudentInfoMapper;
import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;

/**
 * 查询学生数据接口实现类
 * @Author Zhang Da
 * @Date 2020/2/13 15:10
 * @Version 1.0
 */
@SofaService(interfaceType = StudentQueryService.class, bindings = { @SofaServiceBinding(bindingType = "bolt") })
@Component
public class StudentQueryServiceImpl implements StudentQueryService {
    @Resource
    StudentInfoMapper studentInfoMapper;

    @Override
    public StudentInfo queryStudentByStudentNo(String studentNo) {
        return studentInfoMapper.selectByPrimaryKey(studentNo);
    }

    @Override
    public List<StudentInfo> queryStudentsByConditions(String studentNo, String collegeName, String majorName, String grade,
                                                       String className, String admissionTicketNo, Double scoreTotal){
        StudentInfoExample example = new StudentInfoExample();
        StudentInfoExample.Criteria criteria = example.createCriteria();

        //学号
        if (StringUtils.isNotBlank(studentNo)){
            criteria.andStudentNoEqualTo(studentNo);
        }
        //院系
        if (StringUtils.isNotBlank(collegeName)){
            criteria.andCollegeNameEqualTo(collegeName);
        }
        //专业
        if (StringUtils.isNotBlank(majorName)){
            criteria.andMajorNameEqualTo(majorName);
        }
        //年级
        if (StringUtils.isNotBlank(grade)){
            criteria.andGradeEqualTo(grade);
        }
        //班级
        if (StringUtils.isNotBlank(className)){
            criteria.andClassNameEqualTo(className);
        }
        //总分
        if (scoreTotal != null){
            criteria.andScoreTotalEqualTo(scoreTotal);
        }
        //准考证号
        if (StringUtils.isNotBlank(admissionTicketNo)){
            criteria.andAdmissionTicketNoEqualTo(admissionTicketNo);
        }

        return studentInfoMapper.selectByExample(example);
    }
}
